package com.blb.demo2;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

/**
 * 负责写的线程
 */
public class WriteRunnable implements Runnable{

    //输出流
    private ObjectOutputStream outputStream = null;

    public WriteRunnable(ObjectOutputStream outputStream) {
        this.outputStream = outputStream;
    }

    @Override
    public void run() {
        System.out.println("WriteRunnable run");
        Scanner scanner = new Scanner(System.in);
        try {
            while (true) {
                //输入消息发给对方
                System.out.println("输入要说的话：");
                String msg = scanner.nextLine();
                outputStream.writeUTF(msg);
                outputStream.flush();
            }
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
